﻿using ServiceStack.ServiceInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Pacs.Services.Soa
{
    [DataContract]
    public class DTOResponse<T>
    {
        public DTOResponse()
        {
            this.Header = new DTOResponseHeader();
        }
        /// <summary>
        /// 通用返回类型头格式
        /// </summary>
        [DataMember(Name = "header")]
        public DTOResponseHeader Header
        { get; set; }
        ///// <summary>
        ///// ServiceStack 自动异常捕获对象，通常不需要主动赋值
        ///// </summary>
        //[DataMember(Name = "status")]
        //public ResponseStatus Status
        //{ get; set; }
        /// <summary>
        /// 业务主体对象
        /// </summary>
        [DataMember(Name = "body")]
        public T Body
        {
            get;
            set;
        }
        /// <summary>
        /// 设置响应操作成功并且返回具体数据，并置Succeed=true
        /// </summary>
        /// <param name="body">业务数据对象</param>
        public DTOResponse(T body)
        {
            this.Header = new DTOResponseHeader();
            this.Header.Messages = new List<string>();
            this.Body = body;
            this.Header.Succeed = true;
        }
        /// <summary>
        /// 设置响应是否正确返回，并追加返回的信息
        /// </summary>
        /// <param name="msg">信息</param>
        /// <param name="code">信息码</param>
        /// <param name="Succeed">是否正常</param>
        public DTOResponse(bool Succeed, List<string> msg)
        {
            this.Header = new DTOResponseHeader();
            this.Header.Succeed = Succeed;
            this.Header.Messages = msg ?? new List<string>();
        }
        public DTOResponse(bool Succeed, string msg)
        {
            this.Header = new DTOResponseHeader();
            this.Header.Succeed = Succeed;
            this.Header.Messages = new List<string>();
            this.Header.Messages.Add(msg);
        }
        /// <summary>
        /// 设置响应是否正确返回，并追加返回的信息
        /// </summary>
        /// <param name="Succeed">是否正常</param>
        public DTOResponse(bool Succeed)
        {
            this.Header = new DTOResponseHeader();
            this.Header.Messages = new List<string>();
            this.Header.Succeed = Succeed;
        }
    }

    [DataContract]
    public class DTOResponseHeader
    {
        /// <summary>
        /// 业务级操作是否成功
        /// </summary>
        //[DataMember(Name = "Succeed")]
        [DataMember(Name = "succeed")]
        public bool Succeed
        { get; set; }
        /// <summary>
        /// 信息
        /// </summary>
        [DataMember(Name = "messages")]
        public List<string> Messages
        { get; set; }
        /// <summary>
        /// 信息
        /// </summary>
        [DataMember(Name = "attachments")]
        public List<string> Attachments
        { get; set; }
    }
}
